﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PhanMemDoVui.BusinessLogic;
using PhanMemDoVui.BusinessObject;

namespace PhanMemDoVui
{
    public partial class frmWelcome : Form
    {
        public frmWelcome()
        {
            InitializeComponent();
            this.Icon = Properties.Resources.Lamp;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            frmScore fScore = new frmScore();
            this.Hide();
            fScore.Show();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void btn_create_Click(object sender, EventArgs e)
        {
            frmCreateAccount fca = new frmCreateAccount();
            this.Hide();
            fca.Show();
        }

        private void btn_login_Click(object sender, EventArgs e)
        {
            UserBUS user = UserBUS.Instance();
            Profile pr = new Profile();
            if (txt_username.Text == "" || txt_pass.Text == "")
            {
                lab_wrong.Show();
            }
            else
            {
                pr.Username = txt_username.Text;
                pr.Password = txt_pass.Text;
                bool success = user.DangNhap(pr);
                if (success == false)
                    lab_wrong.Show();
                else
                {
                    this.Hide();
                    if (user.IsAdmin() == true)
                    {
                        frmAdmin admin = new frmAdmin();
                        admin.Show();
                    }
                    else
                    {
                        frmCommonUser comm = new frmCommonUser();
                        comm.Show();
                    }
                }
            }
        }

        private void frmWelcome_MaximumSizeChanged(object sender, EventArgs e)
        {
           
        }

        private void frmWelcome_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }
    }
}
